package com.dzt.cloudreader.adapter;

import android.app.Activity;
import android.view.View;
import android.view.animation.OvershootInterpolator;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.dzt.cloudreader.R;
import com.dzt.cloudreader.activity.OneMovieDetailActivity;
import com.dzt.cloudreader.adapter.recycler.RecyclerAdapter;
import com.dzt.cloudreader.adapter.recycler.RecyclerHolder;
import com.dzt.cloudreader.model.HotMovieBean;
import com.dzt.cloudreader.utils.JCommonKit;
import com.dzt.cloudreader.utils.JStringFormatKit;
import com.nineoldandroids.view.ViewHelper;
import com.nineoldandroids.view.ViewPropertyAnimator;

import java.util.List;

/**
 * Created by M02323 on 2017/12/27.
 */

public class HotMovieAdapter extends RecyclerAdapter<HotMovieBean.SubjectsBean> {

	private Activity activity;

	public HotMovieAdapter(Activity activity, List<HotMovieBean.SubjectsBean> datas, int layoutId) {
		super(activity, datas, layoutId);
		this.activity = activity;
	}

	@Override
	public void convert(RecyclerHolder holder, final HotMovieBean.SubjectsBean data, final int position) {

		holder.setImageGlide(R.id.iv_one_photo, data.getImages().getLarge());
		holder.setText(R.id.tv_one_title, data.getTitle());
		holder.setText(R.id.tv_one_directors, JStringFormatKit.formatPerson(data.getDirectors()));
		holder.setText(R.id.tv_one_casts, JStringFormatKit.formatPerson(data.getCasts()));
		holder.setText(R.id.tv_one_genres, JStringFormatKit.formatGenres(data.getGenres()));
		String rating = context.getResources().getString(R.string.string_rating) + data.getRating().getAverage();
		holder.setText(R.id.tv_one_rating_rate, rating);

		View viewColor = holder.findView(R.id.view_color);
		viewColor.setBackgroundColor(JCommonKit.randomColor());

		ViewHelper.setScaleX(holder.itemView, 0.8f);
		ViewHelper.setScaleY(holder.itemView, 0.8f);
		ViewPropertyAnimator.animate(holder.itemView).scaleX(1)
				.setDuration(350).setInterpolator(new OvershootInterpolator()).start();
		ViewPropertyAnimator.animate(holder.itemView).scaleY(1)
				.setDuration(350).setInterpolator(new OvershootInterpolator()).start();

		LinearLayout llOneItem = holder.findView(R.id.ll_one_item);
		final ImageView ivOnePhoto = holder.findView(R.id.iv_one_photo);
		llOneItem.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				OneMovieDetailActivity.start(activity, data, ivOnePhoto);
			}
		});
	}
}
